package com.sj.parksdk.fragment.main;

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.vlayout.layout.GridLayoutHelper;
import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
import com.ruffian.library.widget.RLinearLayout;
import com.ruffian.library.widget.RTextView;
import com.ruffian.library.widget.helper.RTextViewHelper;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.sj.parksdk.R;
import com.sj.parksdk.R2;
import com.sj.parksdk.activity.ActivityQrCode;
import com.sj.parksdk.adapter.base.delegate.SimpleDelegateAdapter;
import com.sj.parksdk.core.BaseFragment;
import com.sj.parksdk.fragment.carmanage.FragmentCarManage;
import com.sj.parksdk.fragment.carmanage.FragmentParkRecord;
import com.sj.parksdk.fragment.carmanage.FragmentParkingPay;
import com.sj.parksdk.fragment.certificate.FragmentCarCertificate;
import com.sj.parksdk.fragment.pay.FragmentPurchasePlan;
import com.sj.parksdk.fragment.pay.FragmentPurchasePlanConfirm;
import com.sj.parksdk.net.http.MyNetApi;
import com.sj.parksdk.net.http.callback.TipRequestCallBack;
import com.sj.parksdk.net.manager.TokenManager;
import com.sj.parksdk.net.request.MGetRequest;
import com.sj.parksdk.net.request.WeatherRequest;
import com.sj.parksdk.net.result.databean.Data_Banners;
import com.sj.parksdk.net.result.databean.Data_Car;
import com.sj.parksdk.net.result.databean.Data_NearbyPark;
import com.sj.parksdk.net.result.databean.Data_OverView;
import com.sj.parksdk.net.result.databean.Data_Weather;
import com.sj.parksdk.setting.Constans;
import com.sj.parksdk.setting.Dictionary;
import com.sj.parksdk.setting.Extras;
import com.sj.parksdk.utils.DemoDataProvider;
import com.sj.parksdk.utils.NavicatUtils;
import com.sj.parksdk.utils.RefreshState;
import com.sj.parksdk.utils.Utils;
import com.sj.parksdk.utils.bdlocation.LocatedInfo;
import com.sj.parksdk.utils.bdlocation.LocationService;
import com.sj.parksdk.utils.minterface.HomeInterface;
import com.sj.parksdk.widget.MRTextView.MRTextView;
import com.sj.parksdk.widget.RadiusImageBanner;
import com.sj.parksdk.widget.sweetalert.SweetAlertDialog;
import com.xuexiang.xhttp2.exception.ApiException;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xpage.core.PageOption;
import com.xuexiang.xpage.enums.CoreAnim;
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
import com.xuexiang.xui.adapter.simple.AdapterItem;
import com.xuexiang.xui.utils.DensityUtils;
import com.xuexiang.xui.utils.ResUtils;
import com.xuexiang.xui.utils.WidgetUtils;
import com.xuexiang.xui.widget.banner.widget.banner.BannerItem;
import com.xuexiang.xui.widget.imageview.ImageLoader;
import com.xuexiang.xui.widget.imageview.strategy.DiskCacheStrategyEnum;
import com.xuexiang.xui.widget.layout.XUILinearLayout;
import com.xuexiang.xui.widget.statelayout.StatefulLayout;
import com.xuexiang.xutil.common.StringUtils;
import com.xuexiang.xutil.net.JsonUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

@Page(anim = CoreAnim.none)
public class FragmentMain extends BaseFragment {

    @BindView(R2.id.tv_weatcher_detail)
    TextView tvWeatcherDetail;
    @BindView(R2.id.recycler_grid)
    RecyclerView recyclerGrid;
    @BindView(R2.id.banner_advertising)
    RadiusImageBanner bannerAdvertising;
    @BindView(R2.id.tv_location)
    TextView tvLocation;
    @BindView(R2.id.iv_refresh)
    ImageView ivRefresh;
    @BindView(R2.id.recycler_nearby)
    RecyclerView recyclerNearby;
    @BindView(R2.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    @BindView(R2.id.ll_state)
    StatefulLayout llState;
    @BindView(R2.id.rl_add_car)
    RelativeLayout rlAddCar;
    @BindView(R2.id.tv_default_car_number)
    TextView tvDefaultCarNumber;
    @BindView(R2.id.rtv_default_car_color)
    RTextView rtvDefaultCarColor;
    @BindView(R2.id.rll_default_car_color)
    RLinearLayout rllDefaultCarColor;
    @BindView(R2.id.rtv_default_car_certificat)
    RTextView rtvDefaultCarCertificat;
    @BindView(R2.id.rtv_exchange_car)
    MRTextView rtvExchangeCar;
    @BindView(R2.id.rtv_default_car_all_record)
    MRTextView rtvDefaultCarAllRecord;
    @BindView(R2.id.tv_default_car_record_count)
    TextView tvDefaultCarRecordCount;
    @BindView(R2.id.ll_default_park_record)
    XUILinearLayout llDefaultParkRecord;
    @BindView(R2.id.ll_default_no_record)
    XUILinearLayout llDefaultNoRecord;
    @BindView(R2.id.tv_default_record_price)
    TextView tvDefaultRecordPrice;
    @BindView(R2.id.rll_default_record_price)
    RLinearLayout rllDefaultRecordPrice;
    @BindView(R2.id.ll_default_record_detail)
    LinearLayout llDefaultRecordDetail;
    @BindView(R2.id.rtv_default_car_wx_autopay)
    MRTextView rtvDefaultCarWxAutopay;
    @BindView(R2.id.rl_top_default)
    RelativeLayout rlTopDefault;
    @BindView(R2.id.tv_weather_countryname)
    TextView tvWeatherCountryname;
    private SimpleDelegateAdapter<AdapterItem> gridAdapter;
    private SimpleDelegateAdapter<Data_NearbyPark> nearParkAdapter;
    private HomeInterface mHomeInterface;

    private ObjectAnimator animator;

    private Data_Car mDefaultCar;

    @Override
    protected int getLayoutId() {
        return R.layout.parksdk_fragment_main;
    }

    @Override
    protected void initViews() {
        initGrid();
        initNearPark();
        initAnimat();
        if (mHomeInterface == null) return;
        mHomeInterface.startLocat();
        initAdvertising();
        initDeraultCar();
    }

    public void initDeraultCar() {
        if (!TokenManager.getInstance().isUserLogined()) {
            rlAddCar.setVisibility(View.VISIBLE);
            rlTopDefault.setVisibility(View.GONE);
            return;
        }
        rlAddCar.setVisibility(View.GONE);
        rlTopDefault.setVisibility(View.VISIBLE);
        queryDefaultCarInfo();
    }

    private void initAnimat() {
        animator = ObjectAnimator.ofFloat(ivRefresh, "rotation", 720f, 0f);
        animator.setDuration(2000);
        animator.setInterpolator(new LinearInterpolator());
        animator.setRepeatCount(10);
    }

    private void initNearPark() {
        nearParkAdapter = new SimpleDelegateAdapter<Data_NearbyPark>(R.layout.parksdk_adapter_nearby_park, new LinearLayoutHelper()) {
            @Override
            protected void bindData(@NonNull RecyclerViewHolder holder, int position, Data_NearbyPark model) {
                if (model == null) return;
                holder.visible(R.id.iv_select, View.GONE);
                holder.text(R.id.tv_name, model.getName());
                holder.text(R.id.tv_address, model.getAddress());
                holder.text(R.id.tv_describe, model.getChargeStandard());
                holder.text(R.id.tv_distance, model.getDistanceStr());
                RTextView tvStatus = holder.findViewById(R.id.tv_status);
                int stateColor = 0;
                if (Dictionary.Park.Park_Colose == model.getStatus()) {
                    tvStatus.setText(ResUtils.getString(R.string.park_closed));
                    stateColor = ResUtils.getColor(R.color.color_9);
                } else if(Dictionary.Park.Park_Green == model.getStatus()){
                    stateColor = ResUtils.getColor(R.color.color_green_remain);
                    tvStatus.setText("剩余"+model.getRemainSpace());
                }else if(Dictionary.Park.Park_Red == model.getStatus()){
                    stateColor = ResUtils.getColor(R.color.color_red_remain);
                    tvStatus.setText("剩余"+model.getRemainSpace());
                }else{
                    stateColor = ResUtils.getColor(R.color.color_tip_orange);
                }
                tvStatus.getHelper().setTextColorNormal(stateColor);
                tvStatus.getHelper().setBorderColorNormal(stateColor);
                ImageView ivThu = (ImageView) holder.findViewById(R.id.iv_image);
                ImageLoader.get().loadImage(ivThu, model.getThumbImage(), ResUtils.getDrawable(R.drawable.xui_ic_default_img), DiskCacheStrategyEnum.NONE);
                holder.click(R.id.ll_item, v -> navigatToPark(model));
            }
        };
        WidgetUtils.initRecyclerView(recyclerNearby, 0);
        recyclerNearby.setAdapter(nearParkAdapter);
    }

    private void gotoPackageBuyConfim(Data_NearbyPark model) {
        PageOption.to(FragmentPurchasePlanConfirm.class)
                .setNewActivity(true)
                .putString(Extras.PARK_NAME, model.getName())
                .putLong(Extras.PARK_ID, model.getId())
                .putString(Extras.PARK_ADDRESS, model.getAddress())
                .putBoolean(Extras.BASE_TYPE, true)
                .open(this);
    }

    /**
     * 导航去目标车场
     *
     * @param item
     */
    private void navigatToPark(Data_NearbyPark item) {
        NavicatUtils.navigat(item.getLongitude(), item.getLatitude(), item.getAddress(), getContext());
    }

    private void initAdvertising() {
        new MGetRequest(MyNetApi.BANNERS).visit().execute(new TipRequestCallBack<List<Data_Banners>>() {
            @Override
            public void onSuccess(List<Data_Banners> list) throws Throwable {
                if (list == null) return;
                updateBanners(list);
            }
        });
    }

    private void updateBanners(List<Data_Banners> list) {
        List<BannerItem> banners = new ArrayList<>();
        for (Data_Banners banner : list) {
            BannerItem item = new BannerItem();
            item.setImgUrl(banner.getImage()).setTitle(Constans.COUPONS_CENTER+TokenManager.getInstance().getToken());
            banners.add(item);
        }
        bannerAdvertising.setSource(banners)
                .setOnItemClickListener((view, bannerItem, position) -> gotoAdDetail(bannerItem) )
                .startScroll();
    }

    private void gotoAdDetail(BannerItem bannerItem) {
        if(checkLogin())Utils.goWeb(getContext(), bannerItem.getTitle());
    }

    private void initGrid() {
        //九宫格菜单
        GridLayoutHelper gridLayoutHelper = new GridLayoutHelper(5);
        gridLayoutHelper.setPadding(0, 16, 0, 0);
        gridLayoutHelper.setVGap(10);
        gridLayoutHelper.setHGap(0);
        gridAdapter = new SimpleDelegateAdapter<AdapterItem>(R.layout.parksdk_adapter_common_grid_item, gridLayoutHelper, DemoDataProvider.getGridItems(getContext())) {
            @Override
            protected void bindData(@NonNull RecyclerViewHolder holder, int position, AdapterItem item) {
                if (item != null) {
                    holder.image(R.id.riv_item,item.getIcon());
                    holder.text(R.id.tv_sub_title, item.getTitle());
                    holder.click(R.id.ll_container, v -> gotoGridItemPage(position));
                }
            }
        };

        WidgetUtils.initGridRecyclerView(recyclerGrid, 5, 0);
        recyclerGrid.setAdapter(gridAdapter);
    }

    private void gotoGridItemPage(int position) {
        switch (position) {
            case 0:
                if (checkLogin()) gotoRecordPay();
                break;
            case 1:
                if (checkLogin()) gotoPurchasePlan();
                break;
            case 2:
                if (checkLogin()) gotoCarManage();
                break;
            case 3:
                if (checkLogin()) gotoParkRecord();
                break;
            case 4:
                gotoOrCode();
                break;
            case 5:

                break;

        }
    }

    private void gotoParkRecord() {
        PageOption.to(FragmentParkingPay.class)
                .putString(Extras.BASE_TYPE, Extras.CAR_SELECTCAR_TYPE_RECORD)
                .setNewActivity(true)
                .open(this);
    }

    private void gotoOrCode() {
        ActivityQrCode.start(this, Extras.REQUEST_CODE_QRCODE, R.style.XQRCodeTheme_Custom);
    }

    private void gotoPurchasePlan() {
        PageOption.to(FragmentPurchasePlan.class)
                .setNewActivity(true)
                .open(this);
    }

    private void gotoCarManage() {
        PageOption.to(FragmentCarManage.class)
                .setNewActivity(true)
                .open(this);
    }

    private void gotoRecordPay() {
        PageOption.to(FragmentParkingPay.class)
                .putString(Extras.BASE_TYPE, Extras.CAR_SELECTCAR_TYPE_PAY)
                .setNewActivity(true)
                .open(this);
    }

    @Override
    protected void initListeners() {
        refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                pageIndex++;
                searchNearByPark(RefreshState.more);
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                pageIndex = 1;
                searchNearByPark(RefreshState.refresh);
                initDeraultCar();
                initAdvertising();
            }
        });
    }


    private void refreshLocation() {
        startAnimat();
        tvLocation.setText(ResUtils.getString(R.string.park_locating));
        mHomeInterface.refreshLocation();
    }

    public void setmHomeInterface(HomeInterface mHomeInterface) {
        this.mHomeInterface = mHomeInterface;
    }

    public void updataLocation(LocatedInfo locationinfo) {
        if (locationinfo == null) return;
        stopAnimat();
        Log.e("location", locationinfo.showString());
        tvLocation.setText(locationinfo.getmLocatedAddress());
        mHomeInterface.stopLocation();
        refreshLayout.autoRefresh();//第一次进入触发自动刷新，演示效果

        refreshWeather();
    }

    private void refreshWeather() {
        new WeatherRequest(MyNetApi.WEATHER_API)
                .params(MyNetApi.WEATHER_CITY, LocationService.get().getLocatedInfo().getDistrictName())
                .execute(new TipRequestCallBack<Data_Weather>() {
                    @Override
                    public void onSuccess(Data_Weather data) throws Throwable {
                        updateWeatherInfo(data);
                    }
                });
    }

    private void updateWeatherInfo(Data_Weather data) {
        if (data == null) return;
        StringBuffer sb = new StringBuffer();
        sb.append((data.getForecast() == null || data.getForecast().size() == 0) ? "" : data.getForecast().get(0).getType())
                .append(data.getWendu())
                .append("℃");
        tvWeatherCountryname.setText(data.getCity());
        tvWeatcherDetail.setText(data.getWendu() + "℃");
    }

    private void startAnimat() {
        if (animator != null && !animator.isRunning()) {
            animator.start();
        }
    }

    private void stopAnimat() {
        if (animator != null && animator.isRunning()) {
            animator.end();
            animator.cancel();
        }
    }

    private int pageIndex = 1;

    private void searchNearByPark(int flag) {
        new MGetRequest(MyNetApi.PARK_LOTS_NEARBY)
                .visit()
                .params(MyNetApi.PakLotsNearby.longitude, LocationService.get().getLocatedInfo().getmLongitude())
                .params(MyNetApi.PakLotsNearby.latitude, LocationService.get().getLocatedInfo().getmLatitude())
                .params(MyNetApi.PakLotsNearby.range, 5.0)
                .params(MyNetApi.PakLotsNearby.pageIndex, pageIndex)
                .params(MyNetApi.PakLotsNearby.pageSize, 20)
                .params(MyNetApi.PakLotsNearby.coordinateType, "BD09")
                .execute(new TipRequestCallBack<Data_NearbyPark>() {
                    @Override
                    public void onSuccess(Data_NearbyPark data) throws Throwable {
                        searchNearBySuccess(data, flag);
                    }

                    @Override
                    public void onError(ApiException e) {
                        super.onError(e);
                        searchNearByError(flag);
                    }
                });
    }

    private void searchNearBySuccess(Data_NearbyPark data, int flag) {
        if (data == null || data.getItems() == null) {
            if (flag == RefreshState.refresh) llState.showCustom(emptyStatus());
            return;
        }
        switch (flag) {
            case RefreshState.refresh:
                if (data.getItems().size() == 0) llState.showCustom(emptyStatus());
                else llState.showContent();
                nearParkAdapter.refresh(data.getItems());
                refreshLayout.finishRefresh();
                if (data.getTotal() == data.getItems().size()) {
                    refreshLayout.setNoMoreData(true);
                }
                break;
            case RefreshState.more:
                nearParkAdapter.loadMore(data.getItems());
                if (data.getTotal() == nearParkAdapter.getData().size()) {
                    refreshLayout.finishLoadMoreWithNoMoreData();
                    break;
                }
                refreshLayout.finishLoadMore();
                break;
        }
    }

    private void searchNearByError(int flag) {
        llState.showError(null);
        switch (flag) {
            case RefreshState.refresh:
                refreshLayout.finishRefresh();
                break;
            case RefreshState.more:
                refreshLayout.finishLoadMore(false);
                break;
        }
    }


    private void queryDefaultCarInfo() {
        queryCarList();
    }

    private void queryCarList() {
        new MGetRequest(MyNetApi.CAR_CARS)
                .user()
                .params(MyNetApi.PageParam.pageIndex, 1)
                .params(MyNetApi.PageParam.pageSize, 100)
                .execute(new TipRequestCallBack<Data_Car>() {
                    @Override
                    public void onSuccess(Data_Car response) throws Throwable {
                        queryCarsSuccess(response);
                    }
                });
    }

    private void queryCarsSuccess(Data_Car data) {
        if (data.getItems() == null || data.getItems().size() == 0) {
            rlAddCar.setVisibility(View.VISIBLE);
            rlTopDefault.setVisibility(View.GONE);
            return;
        }
        List<Data_Car> newCars = data.getItems();
//        Collections.reverse(newCars);
        rlAddCar.setVisibility(View.GONE);
        rlTopDefault.setVisibility(View.VISIBLE);
        Data_Car defaultCar = newCars.get(0);
        updateDefaultCarInfo(defaultCar);
    }

    private void queryChargeOverView(String carNo) {
        new MGetRequest(MyNetApi.CHARGE_OVER_VIEW)
                .user()
                .params("carNo", carNo)
                .execute(new TipRequestCallBack<Data_OverView>() {
                    @Override
                    public void onSuccess(Data_OverView data) throws Throwable {
                        if (data == null) return;
                        llDefaultNoRecord.setVisibility(data.getOrderCount() == 0 ? View.VISIBLE : View.GONE);
                        tvDefaultRecordPrice.setText(data.getTotalFeeString());
                        tvDefaultCarRecordCount.setText("共" + data.getOrderCount() + "条");
                    }
                });
    }

    @OnClick({R2.id.rl_add_car, R2.id.rtv_exchange_car, R2.id.rtv_default_car_all_record, R2.id.ll_default_park_record, R2.id.rll_default_record_price, R2.id.iv_refresh})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.rl_add_car) {
            if (checkLogin()) openNewPage(FragmentAddCar.class);
        } else if (id == R.id.rtv_exchange_car) {
            if (checkLogin())
                openNewPageForResult(FragmentParkingPay.class, Extras.BASE_IS_SELECTED, Extras.BASE_SELECTED, Extras.REQUEST_CAR_SELECTE_CAR);
        } else if (id == R.id.rtv_default_car_all_record) {
            gotoRecord(true);
        } else if (id == R.id.rll_default_record_price) {
            gotoRecord(false);
        } else if (id == R.id.ll_default_park_record) {
            gotoRecord(false);
        } else if (id == R.id.iv_refresh) {
            refreshLocation();
        }
    }

    private void gotoRecord(boolean all) {
        if (!checkLogin()) return;
        if (all && !mDefaultCar.isVerified()) showCetificatFirstDialog();
        else {
            PageOption.to(FragmentParkRecord.class)
                    .putLong(Extras.CAR_ID, mDefaultCar.getId())
                    .putString(Extras.CAR_NUMBER, mDefaultCar.getCarNo())
                    .putBoolean(Extras.CAR_IS_CETIFICAT, mDefaultCar.isVerified())
                    .putString(Extras.CAR_COLOR, mDefaultCar.getPlateColor())
                    .putBoolean(Extras.PARK_ORDER_UNFINISH, !all)
                    .setNewActivity(true)
                    .open(this);
        }
    }

    private void showCetificatFirstDialog() {
        new SweetAlertDialog(getContext(), SweetAlertDialog.NORMAL_CENTER_TITLE_TYPE)
                .setContentMinHeight(DensityUtils.dp2px(100))
                .setContentText(ResUtils.getString(R.string.dialog_certificat_first))
                .setConfirmText(ResUtils.getString(R.string.dialog_button_goto_cetificat))
                .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                    @Override
                    public void onClick(SweetAlertDialog sweetAlertDialog) {
                        gotoCarCetificat();
                        sweetAlertDialog.dismiss();
                    }
                }).setCancelClickListener(null).show();
    }

    //车辆认证
    private void gotoCarCetificat() {
        PageOption.to(FragmentCarCertificate.class)
                .putLong(Extras.CAR_ID, mDefaultCar.getId())
                .putString(Extras.CAR_NUMBER, mDefaultCar.getCarNo())
                .putString(Extras.CAR_COLOR, mDefaultCar.getPlateColor())
                .putBoolean(Extras.CAR_IS_CETIFICAT, mDefaultCar.isVerified())
                .setNewActivity(true)
                .openForResult(this, Extras.REQUEST_CAR_CERTIFICATE);
    }

    @Override
    public void onFragmentResult(int requestCode, int resultCode, Intent data) {
        super.onFragmentResult(requestCode, resultCode, data);
        if (resultCode != Activity.RESULT_OK) return;
        if (data == null) return;
        if (requestCode == Extras.REQUEST_CAR_SELECTE_CAR) updateDefaultCarFormExchange(data);
    }

    private void updateDefaultCarFormExchange(Intent data) {
        String json = data.getStringExtra(Extras.BASE_JSON);
        if (StringUtils.isEmpty(json)) return;
        Data_Car car = JsonUtil.fromJson(json, Data_Car.class);
        if (car == null) return;
        updateDefaultCarInfo(car);
    }

    private void updateDefaultCarInfo(Data_Car defaultCar) {
        mDefaultCar = defaultCar;
        TokenManager.getInstance().setDefaultCar(defaultCar);
        tvDefaultCarNumber.setText(defaultCar.getCarNo());
        rtvDefaultCarCertificat.setVisibility(defaultCar.isVerified() ? View.VISIBLE : View.GONE);
        rtvDefaultCarColor.setText(Dictionary.Car.PlateColor.PlateColorNameMap.get(defaultCar.getPlateColor()));
        RTextViewHelper rtvCarColorHeler = rtvDefaultCarColor.getHelper();
        int color = Dictionary.Car.PlateColor.PalteColorMap.get(defaultCar.getPlateColor());
        rtvCarColorHeler.setBackgroundColorNormal(ResUtils.getColor(color));
        rtvCarColorHeler.setTextColorNormal(ResUtils.getColor(Dictionary.Car.PlateColor.White.equals(defaultCar.getPlateColor()) ? R.color.color_3 : R.color.color_white));
        rtvCarColorHeler.setBorderWidthNormal(DensityUtils.dp2px(Dictionary.Car.PlateColor.White.equals(defaultCar.getPlateColor()) ? 1 : 0));
        rllDefaultCarColor.getHelper().setBorderColorNormal(ResUtils.getColor(Dictionary.Car.PlateColor.White.equals(defaultCar.getPlateColor()) ?R.color.color_3:color));
        queryChargeOverView(defaultCar.getCarNo());
    }
//
    @Override
    public void onResume() {
        super.onResume();
        if(TokenManager.getInstance().onRefreshPaySuccess()) {
            initDeraultCar();
            TokenManager.getInstance().refreshPayState(false);
        }
    }
}
